package node;

import lexer.LexType;
import parser.Parser;

import java.io.IOException;
import java.util.List;

public class BlockNode extends ASTNode {
    public final String name = "<Block>";
    // Block → '{' { BlockItem } '}'
    private List<BlockItemNode> blockItemNodes;
    public int symbolTableIndex;

    public BlockNode(List<BlockItemNode> blockItemNodes, int symbolTableIndex) {
        this.blockItemNodes = blockItemNodes;
        this.symbolTableIndex = symbolTableIndex;
    }

    @Override
    public void show() throws IOException {
        Parser.parserWriter.write(LexType.LBRACE + " " + "{" + "\n");
        for (BlockItemNode blockItemNode : blockItemNodes) {
            blockItemNode.show();
        }
        Parser.parserWriter.write(LexType.RBRACE + " " + "}" + "\n");
        Parser.parserWriter.write(name + "\n");
    }

    public List<BlockItemNode> getBlockItemNodes() {
        return blockItemNodes;
    }

}
